<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="申请日期" prop="createTime">
        <el-date-picker clearable
                        v-model="queryParams.createTime"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择申请日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="申请人" prop="memberName">
        <el-input
          v-model="queryParams.memberName"
          placeholder="请输入申请人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="memberPhone">
        <el-input
          v-model="queryParams.memberPhone"
          placeholder="请输入申请人联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="recordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="申请流水号" align="center" prop="recordno" />
      <el-table-column label="申请时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="申请人名称" align="center" prop="memberName" />
      <el-table-column label="申请人电话" align="center" prop="memberPhone" />
      <el-table-column label="提现金额" align="center" prop="withdrawmoney" />

      <el-table-column label="收款信息" align="center" prop="withdrawmoney" >
        <template slot-scope="scope">
          <div>
            <div>持卡人名称:{{scope.row.bankaccoutname}}</div>
            <div>开户行名称:{{scope.row.bankname}}</div>
            <div>卡号:{{scope.row.bankcardno}}</div>
            <div>支行名称:{{scope.row.bankprovince}}{{scope.row.bankcity}}{{scope.row.banksubbranch}}</div>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" >
        <template slot-scope="scope">
          <span v-if="scope.row.status===1">待支付</span>
          <span v-if="scope.row.status===2">支付中</span>
          <span v-if="scope.row.status===3">已拒绝</span>
          <span v-if="scope.row.status===4">已支付</span>
          <span v-if="scope.row.status===5">支付失败</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="note" />
      <el-table-column label="审批时间" align="center" prop="checktime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checktime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleConfirm(scope.row)"
            v-hasPermi="['system:record:edit']"
          >确认支付</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleReject(scope.row)"
            v-hasPermi="['system:record:remove']"
          >拒绝申请</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listRecord, getRecord, delRecord, addRecord, updateRecord } from "@/api/smy/distributorWithdrawRecord";

export default {
  name: "Record",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bankaccoutname: null,
        bankcardno: null,
        bankcity: null,
        bankname: null,
        bankprovince: null,
        banksubbranch: null,
        checktime: null,
        createtime: null,
        note: null,
        paytype: null,
        recordno: null,
        status: null,
        withdrawmoney: null,
        distributorId: null,
        operatorId: null,
        recordId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        paytype: [
          { required: true, message: "$comment不能为空", trigger: "change" }
        ],
        status: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
        withdrawmoney: [
          { required: true, message: "$comment不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        bankaccoutname: null,
        bankcardno: null,
        bankcity: null,
        bankname: null,
        bankprovince: null,
        banksubbranch: null,
        checktime: null,
        createtime: null,
        note: null,
        paytype: null,
        recordno: null,
        status: 0,
        withdrawmoney: null,
        distributorId: null,
        operatorId: null,
        recordId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    handleConfirm(row){
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认支付编号为"' + ids + '"的提现申请单？').then(function() {
        // return delRecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {});
    },
    handleReject(row){
      const ids = row.id || this.ids;
      this.$modal.confirm('是否拒绝编号为"' + ids + '"的提现申请单？').then(function() {
        // return delRecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("操作成功");
      }).catch(() => {});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项？').then(function() {
        return delRecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
  }
};
</script>
